package com.gpframework.module.controller.purchase;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.purchase.domain.GpPurchaseIncomingInspectWidth;
import com.gpframework.module.purchase.domain.vo.GpPurchaseIncomingInspectWidthVo;
import com.gpframework.module.purchase.domain.req.GpPurchaseIncomingInspectWidthReq;
import com.gpframework.module.purchase.domain.req.GpPurchaseIncomingInspectWidthAdd;
import com.gpframework.module.purchase.domain.req.GpPurchaseIncomingInspectWidthUpdate;
import com.gpframework.module.purchase.service.IGpPurchaseIncomingInspectWidthService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpPurchaseIncomingInspectWidthController
 * @Author gpframework
 * @Date 2024-01-09
 * @Version 1.0.0
 * @Description 采购来料检验单幅宽Controller
 */
@Validated
@Api(tags = "采购来料检验单幅宽")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/purchase/incomingwidth" )
public class GpPurchaseIncomingInspectWidthController extends BaseController {

    private final IGpPurchaseIncomingInspectWidthService iGpPurchaseIncomingInspectWidthService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2024-01-09
  * @Param gpPurchaseIncomingInspectWidth
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:list')")
    @GetMapping("/list")
    public TableDataInfo<GpPurchaseIncomingInspectWidthVo> list(GpPurchaseIncomingInspectWidthReq gpPurchaseIncomingInspectWidthReq)
    {
        startPage();
        QueryWrapper<GpPurchaseIncomingInspectWidth> lqw = new QueryWrapper<GpPurchaseIncomingInspectWidth>();
        gpPurchaseIncomingInspectWidthReq.generatorQuery(lqw,true);
        List<GpPurchaseIncomingInspectWidthVo> list = iGpPurchaseIncomingInspectWidthService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpPurchaseIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:add')" )
    @Log(title = "添加采购来料检验单幅宽" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpPurchaseIncomingInspectWidthAdd gpPurchaseIncomingInspectWidthAdd) {
        GpPurchaseIncomingInspectWidth gpPurchaseIncomingInspectWidth = Convert.convert(new TypeReference<GpPurchaseIncomingInspectWidth>() {}, gpPurchaseIncomingInspectWidthAdd);
        return toAjax(iGpPurchaseIncomingInspectWidthService.save(gpPurchaseIncomingInspectWidth) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpPurchaseIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:edit')" )
    @Log(title = "修改采购来料检验单幅宽" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpPurchaseIncomingInspectWidthUpdate gpPurchaseIncomingInspectWidthUpdate) {
        GpPurchaseIncomingInspectWidth gpPurchaseIncomingInspectWidth = Convert.convert(new TypeReference<GpPurchaseIncomingInspectWidth>() {}, gpPurchaseIncomingInspectWidthUpdate);
        return toAjax(iGpPurchaseIncomingInspectWidthService.updateById(gpPurchaseIncomingInspectWidth) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpPurchaseIncomingInspectWidth
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:export')" )
    @Log(title = "导出采购来料检验单幅宽" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpPurchaseIncomingInspectWidthReq gpPurchaseIncomingInspectWidthReq) {
        QueryWrapper<GpPurchaseIncomingInspectWidth> lqw = new QueryWrapper<GpPurchaseIncomingInspectWidth>();
        gpPurchaseIncomingInspectWidthReq.generatorQuery(lqw,true);
        List<GpPurchaseIncomingInspectWidthVo> list = iGpPurchaseIncomingInspectWidthService.listVo(lqw);
        ExcelUtil<GpPurchaseIncomingInspectWidthVo> util = new ExcelUtil<GpPurchaseIncomingInspectWidthVo>(GpPurchaseIncomingInspectWidthVo. class);
        return util.exportExcel(list, "incomingwidth" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpPurchaseIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpPurchaseIncomingInspectWidthVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpPurchaseIncomingInspectWidthService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpPurchaseIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('purchase:incomingwidth:remove')" )
    @Log(title = "删除采购来料检验单幅宽" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpPurchaseIncomingInspectWidthService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
